#include <QCoreApplication>
#include "Singleton.h"

class Foo {
public:
    void doSomething() {
        std::cout << "Foo instance: " << this << " is doing something." << std::endl;
    }

private:
    friend class Singleton<Foo>; // 允许 Singleton<Foo> 访问私有构造函数
    Foo() {
        std::cout << "Foo constructed" << std::endl;
    }
    ~Foo() {
        std::cout << "Foo destructed" << std::endl;
    }
};

class Bar {
public:
    void doSomethingElse() {
        std::cout << "Bar instance: " << this << " is doing something else." << std::endl;
    }

private:
    friend class Singleton<Bar>; // 允许 Singleton<Bar> 访问私有构造函数
    Bar() {
        std::cout << "Bar constructed" << std::endl;
    }
    ~Bar() {
        std::cout << "Bar destructed" << std::endl;
    }
};

int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);

    // 获取 Singleton 实例并调用方法
    Foo* fooInstance = Singleton<Foo>::getInstance();
    fooInstance->doSomething();

    Foo* fooInstance2 = Singleton<Foo>::getInstance();
    fooInstance2->doSomething();

    Bar* barInstance = Singleton<Bar>::getInstance();
    barInstance->doSomethingElse();

    return a.exec();
}
